package cn.stylefeng.guns.modular.customer.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.customer.entity.Withdraw;
import cn.stylefeng.guns.modular.customer.mapper.WithdrawMapper;
import  cn.stylefeng.guns.modular.customer.service.WithdrawService;
import cn.stylefeng.guns.modular.customer.wrapper.RebateWarpper;
import cn.stylefeng.guns.modular.customer.wrapper.WithdrawWarpper;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 提现记录表 服务实现类
 * </p>
 *
 * @author typ
 * @since 2021-04-25
 */
@Service
public class WithdrawServiceImpl extends ServiceImpl<WithdrawMapper, Withdraw> implements WithdrawService {

    @Override
    public void add(Withdraw param){
        Withdraw entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(Withdraw param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(Withdraw param){
        Withdraw oldEntity = getOldEntity(param);
        Withdraw newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public Withdraw findBySpec(Withdraw param){
        return null;
    }

    @Override
    public List<Withdraw> findListBySpec(Withdraw param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(Withdraw param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageMapList(pageContext, param);
        Page<Map<String, Object>> wrap = new WithdrawWarpper((Page<Map<String, Object>>) page).wrap();
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(Withdraw param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private Withdraw getOldEntity(Withdraw param) {
        return this.getById(getKey(param));
    }

    private Withdraw getEntity(Withdraw param) {
        Withdraw entity = new Withdraw();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
